package com.qf.zyh.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: COS
 * @time: 2021/10/22 11:43
 * @description:
 */
public class DateUtil {
    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * @author: COS
     * @return:
     * @time: 2021/10/22 11:45
     * @description: 字符串转日期
     */
    public static Date stringToDate(String date) {
        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @author: COS
     * @return:
     * @time: 2021/10/22 11:45
     * @description: 日期转字符串
     */
    public static String dateToString(Date date) {
        return sdf.format(date);
    }
    /**
     *
     * @author: COS
     * @return:
     * @time: 2021/10/22 11:46
     * @description: util的日期转为sql的日期
     */
    public static java.sql.Date utilDateToSqlDate(Date datd){
        return new java.sql.Date(datd.getTime());
    }
    /**
     *
     * @author: COS
     * @return:
     * @time: 2021/10/22 11:46
     * @description: 字符串为sql的日期
     */
    public static java.sql.Date StringToSqlDate(String date){
        return new java.sql.Date(stringToDate(date).getTime());
    }

}
